package com.ff.discounts.component.tab.home

import androidx.lifecycle.viewModelScope
import com.ff.discounts.R
import com.ff.discounts.model.BaseViewModel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.launch

/**
 * 最近观看的VM
 * @author: fufang
 * @date: 2023/10/20
 */
class HistoryViewModel :BaseViewModel(){

    private val _data = MutableSharedFlow<List<HistoryData>>()
    val data : Flow<List<HistoryData>> = _data

    fun loadData(){
        setData(HistoryViewModel.historyDataList)
    }

    private fun setData(datum: MutableList<HistoryData>){
        if(datum.size < 4){
            // 添加追剧按钮
            datum.add(HistoryData(R.drawable.follow_add,"", ""),)
        }
        viewModelScope.launch {
            _data.emit(datum)
        }
    }

    companion object{
        private val historyDataList = mutableListOf<HistoryData>(
            HistoryData(R.drawable.photo,"极品校花爱上我", "第五集"),
            HistoryData(R.drawable.photo,"极品校花爱上我", "第五集"),
            HistoryData(R.drawable.photo,"极品校花爱上我", "第五集"),

        )
    }
}